|
|
|
| |
|
|
|
|
Visual Basic 5 ships with an API viewer that enables you to search for a particular API call and then copy and paste the information from the viewer directly into your Visual Basic 5 application. |
|
|
|
|
|
|
|
|
|
|
After you declare the basic APIs, you need to create a set of Visual Basic routines that use these APIs to perform the low-level operations needed to execute ODBC commands from Visual Basic. After the low-level routines, you write a few mid-level functions that hide most of the grittier features of API programming. Finally, you create a few high-level routines you can use from any Visual Basic data-entry form to start off and maintain your ODBC connections. |
|
|
|
|
|
|
|
|
Dozens of API calls for the ODBC interface are possible. You can write calls that enable you to inspect the type of ODBC driver you are using, to inspect the various details of the data source (database name, format, and so on), to gather information about the dataset (column names, data types for each field, length of each field, and so on), and to actually connect to the data source and move data to and from the ODBC data source. For this lesson, you focus only on those routines needed to move data back and forth through the ODBC interface. |
|
|
|
|
|
|
|
|
Before you start coding the API calls and wrapper routines, you need to review the basic sequence of ODBC events required to connect to and share data with a registered ODBC data source. Several preliminary steps are involved before you actually can get any data from an ODBC data source. These steps involve defining an environment space for the ODBC connection, completing the actual connection, and then establishing an area of memory for passing data back and forth. Many of the API calls require or return unique values (called handles) to identify the memory spaces reserved for the ODBC interface. Figure 19.7 shows these operations. Most of the preliminary work for establishing an ODBC connection involves creating the handles you use throughout your program. |
|
|
|
|
|
|
|
|
After the connection is established, you easily can share data with the target data source by using standard SQL statements. You can select a set of rows by using the SELECT_FROM statement. Whenever you request a dataset from the ODBC source, you need to go through several steps to actually pass the rows and columns from the source to your Visual Basic program. First, you execute the SQL statement. Then, to receive the dataset, you must determine the number of columns to receive and use that information to tell ODBC to queue up a row of data and send you each column in the row. You do this until you have received all the rows in the dataset. Figure 19.8 illustrates the process of executing the SELECT statement and collecting the resulting data. |
|
|
|
|
|